<script setup lang="ts">
import { useMemberStore } from '@/stores'

const memberStore = useMemberStore()
const baseURL = 'http://172.16.7.64:5002'
// 退出登录
const onLogout = () => {
  // 显示模态框
  uni.showModal({
    content: '是否退出登录',
    success(res) {
      // 如果点击了确认
      if (res.confirm) {
        // 调用后端的退出登录接口
        uni.request({
          url: baseURL + '/sso/logout', // 替换为实际的后端地址
          method: 'POST',
          success(response) {
            // 如果后端成功清除 了Redis中的token
            if (response.statusCode === 200) {
              // 清理本地的用户信息和token
              memberStore.clearProfile()
              // 返回上一级
              uni.navigateBack()
            } else {
              // 处理错误情况
              uni.showToast({
                title: '退出登录失败',
                icon: 'none'
              })
            }
          },
          fail() {
            // 网络请求失败的处理
            uni.showToast({
              title: '网络请求失败',
              icon: 'none'
            })
          }
        })
      }
    },
  })
}
</script>


<template>
  <view class="viewport">
    <!-- 列表1 -->
    <view class="list" v-if="memberStore.profile">
      <navigator url="/pagesMember/address/address" hover-class="none" class="item arrow">
        我的收货地址
      </navigator>
    </view>
    <!-- 列表2 -->
    <view class="list">
      <button hover-class="none" class="item arrow" open-type="openSetting">授权管理</button>
      <button hover-class="none" class="item arrow" open-type="feedback">问题反馈</button>
      <button hover-class="none" class="item arrow" open-type="contact">联系我们</button>
    </view>
    <!-- 列表3 -->
    <view class="list">
      <navigator hover-class="none" class="item arrow" url=" ">关于嘉会医疗</navigator>
    </view>
    <!-- 操作按钮 -->
    <view class="action" v-if="memberStore.profile">
      <view @tap="onLogout" class="button">退出登录</view>
    </view>
  </view>
</template>

<style lang="scss">
page {
  background-color: #f4f4f4;
}

.viewport {
  padding: 20rpx;
}

/* 列表 */
.list {
  padding: 0 20rpx;
  background-color: #fff;
  margin-bottom: 20rpx;
  border-radius: 10rpx;

  .item {
    line-height: 90rpx;
    padding-left: 10rpx;
    font-size: 30rpx;
    color: #333;
    border-top: 1rpx solid #ddd;
    position: relative;
    text-align: left;
    border-radius: 0;
    background-color: #fff;

    &::after {
      width: auto;
      height: auto;
      left: auto;
      border: none;
    }

    &:first-child {
      border: none;
    }

    &::after {
      right: 5rpx;
    }
  }

  .arrow::after {
    content: '\e6c2';
    position: absolute;
    top: 50%;
    color: #ccc;
    font-family: 'erabbit' !important;
    font-size: 32rpx;
    transform: translateY(-50%);
  }
}

/* 操作按钮 */
.action {
  text-align: center;
  line-height: 90rpx;
  margin-top: 40rpx;
  font-size: 32rpx;
  color: #333;

  .button {
    background-color: #fff;
    margin-bottom: 20rpx;
    border-radius: 10rpx;
  }
}
</style>
